package com.hero.tweaks.ui.fragments;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import com.hero.tweaks.R;
import com.hero.tweaks.util.AxisPreferenceFragment;
import com.hero.tweaks.util.Constants;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.app.AlertDialog;

public class AboutRenovate extends AxisPreferenceFragment implements
		OnPreferenceClickListener, Constants {

	public static final String TAG = "About";
	//public static final String PREF_INFO = "pref_info";
	public Preference mRepo;
	public Preference mNightly;
	public Preference mPro;
	public Preference mMwilky;
	public Preference mHero;
	public Preference mFisha;
	public Preference mGuy;
	public Preference mJonas;
	public Preference mSoldier;
	public Preference mRaymond;
	public Preference mInfo;

	String Url = "";
	String donate = "";
	String twitter = "";
	String name = "";
	String rom = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setTitle(R.string.t_about);

		addPreferencesFromResource(R.xml.prefs_about_ren);
		
		//mInfo = findPreference(PREF_INFO);
		//mInfo.setOnPreferenceClickListener(this);

		mRepo = findPreference(PREF_REPO);
		mRepo.setOnPreferenceClickListener(this);

		mNightly = findPreference(PREF_NIGHTLY);
		mNightly.setOnPreferenceClickListener(this);

		mPro = findPreference(PREF_PRO);
		mPro.setOnPreferenceClickListener(this);

		mMwilky = findPreference(TEAM_MWILKY);
		mMwilky.setOnPreferenceClickListener(this);

		mHero = findPreference(TEAM_HERO);
		mHero.setOnPreferenceClickListener(this);

		mFisha = findPreference(TEAM_FISHA);
		mFisha.setOnPreferenceClickListener(this);

		mGuy = findPreference(TEAM_GUY);
		mGuy.setOnPreferenceClickListener(this);

		mSoldier = findPreference(TEAM_SOLDIER);
		mSoldier.setOnPreferenceClickListener(this);

		mJonas = findPreference(TEAM_JONAS);
		mJonas.setOnPreferenceClickListener(this);

		mRaymond = findPreference(TEAM_RAYMOND);
		mRaymond.setOnPreferenceClickListener(this);

	}

	@Override
	public boolean onPreferenceClick(Preference preference) {
		
		if (preference == mInfo) {
			AlertDialog.Builder builder = new AlertDialog.Builder(
					getActivity());
			builder.setTitle(getString(R.string.info))
					.setMessage(getString(R.string.tweaks_info_msg))
					.setPositiveButton(getString(R.string.ok),
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int id) {

								}
							});

			AlertDialog alertDialog = builder.create();
			alertDialog.show();
			// alertDialog.setCancelable(false);

			alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
		}

		if (preference == mRepo) {
			Uri uri = Uri
					.parse("https://docs.google.com/document/d/1szBh6lcx29ABRovtQqhz2XDHBXMXoyuAITaXsiEciiY/edit?usp=sharing");
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
		}

		if (preference == mNightly) {
			Uri uri = Uri
					.parse("http://renovate-themes.de/renovate-m8-s7-dl/");
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
		}

		if (preference == mPro) {
			Uri uri = Uri
					.parse("https://play.google.com/store/apps/details?id=com.hero.tweaks.pro");
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
		}

		if (preference == mMwilky) {
			AlertDialog.Builder builder = new AlertDialog.Builder(
					getActivity());
			builder.setTitle(R.string.team_mwilky)
					.setNegativeButton(android.R.string.cancel, null)
					.setItems(R.array.team_generic,
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int id) {
									getResources().getStringArray(
											R.array.team_generic);

									if (id == 0) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/member.php?u=3699616");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									} else if (id == 1) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/donatetome.php?u=3699616");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									}
								}
							})

					.create();
			builder.show();
		}

		if (preference == mHero) {
			AlertDialog.Builder builder = new AlertDialog.Builder(
					getActivity());
			builder.setTitle(R.string.team_hero)
					.setNegativeButton(android.R.string.cancel, null)
					.setItems(R.array.team_renovate,
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int id) {
									getResources().getStringArray(
											R.array.team_renovate);

									if (id == 0) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/member.php?u=3057569");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									} else if (id == 1) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/donatetome.php?u=3057569");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									} else if (id == 2) {
										Uri uri = Uri
												.parse("http://twitter.com/cHerochen");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									}
								}
							})

					.create();
			builder.show();
		}
		if (preference == mFisha) {
			AlertDialog.Builder builder = new AlertDialog.Builder(
					getActivity());
			builder.setTitle(R.string.team_fisha)
					.setNegativeButton(android.R.string.cancel, null)
					.setItems(R.array.team_generic,
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int id) {
									getResources().getStringArray(
											R.array.team_generic);

									if (id == 0) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/member.php?u=704359");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									} else if (id == 1) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/donatetome.php?u=704359");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									}
								}
							})

					.create();
			builder.show();
		}
		if (preference == mGuy) {
			AlertDialog.Builder builder = new AlertDialog.Builder(
					getActivity());
			builder.setTitle(R.string.team_guy)
					.setNegativeButton(android.R.string.cancel, null)
					.setItems(R.array.team_generic,
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int id) {
									getResources().getStringArray(
											R.array.team_generic);

									if (id == 0) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/member.php?u=517854");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									} else if (id == 1) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/donatetome.php?u=517854");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									}
								}
							})

					.create();
			builder.show();
		}
		if (preference == mSoldier) {
			AlertDialog.Builder builder = new AlertDialog.Builder(
					getActivity());
			builder.setTitle(R.string.team_soldier)
					.setNegativeButton(android.R.string.cancel, null)
					.setItems(R.array.team_generic,
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int id) {
									getResources().getStringArray(
											R.array.team_generic);

									if (id == 0) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/member.php?u=4860093");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									} else if (id == 1) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/donatetome.php?u=4860093");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									}
								}
							})

					.create();
			builder.show();
		}
		if (preference == mJonas) {
			AlertDialog.Builder builder = new AlertDialog.Builder(
					getActivity());
			builder.setTitle(R.string.team_jonas)
					.setNegativeButton(android.R.string.cancel, null)
					.setItems(R.array.team_generic,
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int id) {
									getResources().getStringArray(
											R.array.team_generic);

									if (id == 0) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/member.php?u=2262596");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									} else if (id == 1) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/donatetome.php?u=2262596");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									}
								}
							})

					.create();
			builder.show();
		}
		if (preference == mRaymond) {
			AlertDialog.Builder builder = new AlertDialog.Builder(
					getActivity());
			builder.setTitle(R.string.team_raymond)
					.setNegativeButton(android.R.string.cancel, null)
					.setItems(R.array.team_generic,
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int id) {
									getResources().getStringArray(
											R.array.team_generic);

									if (id == 0) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/member.php?u=4380624");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									} else if (id == 1) {
										Uri uri = Uri
												.parse("http://forum.xda-developers.com/donatetome.php?u=4380624");
										Intent intent = new Intent(
												Intent.ACTION_VIEW, uri);
										startActivity(intent);
									}
								}
							})

					.create();
			builder.show();
		}
		return false;
	}

}
